#pragma once

#pragma pack(1)

struct M2Vertex
{
	float x, y, z;
	ui8 boneweight[4];
	ui8 boneindices[4];
	float normalevector[3];
	float texturecoords[2];
	float unk[2];
};

struct VertexF
{
	float x, y, z;
};

struct M2FileHeader
{
	char signature[4];
	char version[4];
	ui32 namelength;
	ui32 nameoffset;
	ui32 nglobalflags;
	ui32 nglobalsequences;
	ui32 ofsGlobalSequences;
	ui32 nanimations;
	ui32 ofsAnimation;
	ui32 nanimationlookup;
	ui32 ofsAnimationLookUp;
	ui32 nbones;
	ui32 ofsBones;
	ui32 nkeybones;
	ui32 ofsKeyBones;
	ui32 nvertices;
	ui32 ofsVertices;
	ui32 nViews;
	ui32 nColors;
	ui32 ofsColors;
	ui32 nTextures;
	ui32 ofsTextures;
	ui32 nTransparencies;
	ui32 ofsTransparencies;
	ui32 nTexAnims;
	ui32 ofsTexAnims;
	ui32 nTexReplace;
	ui32 ofsTexReplace;
	ui32 nRenderFlags;
	ui32 ofsRenderFlags;
	ui32 nBoneLookUp;
	ui32 ofsBoneLookUp;
	ui32 nTexLookUp;
	ui32 ofsTexLookUp;
	ui32 nTexUnits;
	ui32 ofsTexUnits;
	ui32 nTransLookUps;
	ui32 ofsTransLookUps;
	ui32 nTexAnimLookUps;
	ui32 ofsTexAnimLookUps;
	VertexF vertexBox[2];
	float vertexRadius;
	VertexF boundingBox[2];
	float boundingRadius;
	ui32 nBoundingTriangles;
	ui32 ofsBoundingTriangles;
	ui32 nBoundingVertex;
	ui32 ofsBoundingVertex;
	ui32 nBoundingNormals;
	ui32 ofsBoundingNormals;
	ui32 nAttachments;
	ui32 ofsAttachments;
	ui32 nAttachLookUps;
	ui32 ofsAttachLookUps;
	ui32 nAttachments_2;
	ui32 ofsAttackments_2;
	ui32 nLights;
	ui32 ofsLights;
	ui32 nCameras;
	ui32 ofsCameras;
	ui32 nCameraLookUp;
	ui32 ofsCameraLookUp;
	ui32 nRibbonEmitters;
	ui32 ofsRibbonEmitters;
	ui32 nParticleEmitters;
	ui32 ofsParticleEmitters;
};

struct SKINView
{
	ui32 ID;
	ui32 nIndices;
	ui32 ofsIndices;
	ui32 nTriangles;
	ui32 ofsTriangles;
	ui32 nProperties;
	ui32 ofsProperties;
	ui32 nSubMeshes;
	ui32 ofsSubMeshes;
	ui32 nTextureUnits;
	ui32 ofsTextureUnits;
	ui32 bones;
};

struct SKINSubMesh
{
	ui32 ID;
	ui16 startVertex;
	ui16 nVertices;
	ui16 startTriangle;
	ui16 nTriangles;
	ui16 nBones;
	ui16 startBones;
	ui16 unk1;
	ui16 unk2;
	float bounding[2][3];
	float radius;
};

struct SKINTexUnit
{
	ui16 flags;
	ui16 shading;
	ui16 SubMeshIndex_01;
	ui16 SubMeshIndex_02;
	ui16 ColorIndex;
	ui16 RenderFlags;
	ui16 TexUnitNumber;
	ui16 Mode;
	ui16 Texture;
	ui16 TexUnitNumber2;
	ui16 Transparency;
	ui16 TextureAnim;
};

struct M2ModelPass
{
	ui16 indexStart, indexCount, vertexStart, vertexEnd;
	ui32 texture, texture2;
	bool usetex2, useenvmap, cull, trans, unlit, nozwrite;
	float p;	
	i16 texanim, color, opacity, blendmode;
	i16 order;
};

struct M2ModelTexture
{
	ui32 type;
	ui32 flags;
	ui32 nameLen;
	ui32 nameOfs;
};

#pragma pack()